Print the right URL for `cargo login`
authorAlex Crichton <alex@alexcrichton.com>
Tue, 25 Nov 2014 05:50:14 +0000 (21:50 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 25 Nov 2014 05:50:14 +0000 (21:50 -0800)
Closes #968

src/bin/cargo.rs
src/bin/login.rs

index 40d459b9b86dc8e0fe39b6b8d1c9f436a07d73b0..2598bf340a55b909fc487096b33c1725fbd02e12 100644 (file)
@@ -3,8 +3,7 @@
 
 extern crate serialize;
 #[phase(plugin, link)] extern crate log;
-
-extern crate cargo;
+#[phase(plugin, link)] extern crate cargo;
 
 use std::collections::TreeSet;
 use std::os;
index ad4c4bbc48b32c7106f4c41ee011b748809dccac..7e9a3c9a183ee3dc969d05a072386afa3805dd6a 100644 (file)
@@ -1,9 +1,9 @@
 use std::io;
 
 use cargo::ops;
-use cargo::core::{MultiShell};
+use cargo::core::{MultiShell, SourceId, Source};
 use cargo::sources::RegistrySource;
-use cargo::util::{CliResult, CliError};
+use cargo::util::{CliResult, CliError, Config};
 
 #[deriving(Decodable)]
 struct Options {
@@ -30,12 +30,20 @@ pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>
     let token = match options.arg_token.clone() {
         Some(token) => token,
         None => {
-            let default = RegistrySource::url().unwrap().to_string();
-            let host = options.flag_host.unwrap_or(default);
-            println!("please visit {}/me and paste the API Token below", host);
-            try!(io::stdin().read_line().map_err(|e| {
-                CliError::from_boxed(box e, 101)
-            }))
+            let err = (|| {
+                let config = try!(Config::new(shell, None, None));
+                let src = try!(SourceId::for_central());
+                let mut src = RegistrySource::new(&src, &config);
+                try!(src.update());
+                let config = try!(src.config());
+                let host = options.flag_host.clone().unwrap_or(config.api);
+                println!("please visit {}me and paste the API Token below",
+                         host);
+                let line = try!(io::stdin().read_line());
+                Ok(line)
+            })();
+
+            try!(err.map_err(|e| CliError::from_boxed(e, 101)))
         }
     };